<div class="layui-fluid" lay-title="流程角色表单">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="" lay-filter="form-group">
                <div class="layui-form-item">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" lay-verify="required" autocomplete="off" placeholder="请输入名称" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="form-group-submit">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    layui.use(['jquery', 'admin', 'form', 'layer'], function () {
        var $ = layui.jquery
            , layer = layui.layer
            , form = layui.form
            , admin = layui.admin;

        var oaGroup = {};
        var id = POPUP_DATA.id;
        var table = POPUP_DATA.table;

        form.render(null, 'form-group');

        if(id){
            // 初始化
            admin.get({
                type: 'get',
                url: '/activiti/groupInfo/' + id,
                dataType: 'json',
                success: function (data) {
                    oaGroup = data.oaGroup;
                    if (oaGroup) {
                        form.val("form-group", {
                            "name": oaGroup.name // "name": "value"
                        });
                    }
                }
            });
        }

        /* 监听提交 */
        form.on('submit(form-group-submit)', function (data) {
            var field = data.field;
            var groupData = {};
            var url = "/activiti/groupSave";
            groupData.name = field.name;
            if(id){
                groupData.id = id;
            }
            groupData.type = 1;
            admin.post({
                url: url,
                /*contentType: "application/json",*/
                data: {id:id,name:field.name},
                success: function (res) {
                    //$(".layui-btn").removeClass("layui-btn-disabled");
                    if (res.code == 0) {
                        // 提醒保存成功，关闭当前弹窗
                        layer.msg(res.msg);
                        layer.closeAll();
                        //刷新
                        table.reload('list-table-oagroup', {
                            url: '/activiti/groupPage?token=' + admin.loginToken,
                            page: {
                                curr: 1
                            }
                        })
                    } else {
                        layer.msg(res.msg);
                    }
                }
            });
            return false;
        });
    });
</script>